<?php if(!defined('HDPHP_PATH'))exit;C('SHOW_NOTICE',FALSE);?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title></title>

	<link rel="stylesheet" href="http://127.0.0.1/huaweishop/Static/Admin/Bootstrap/Css/bootstrap.min.css" />
	<link rel="stylesheet" href="http://127.0.0.1/huaweishop/Static/Admin/Css/common.css" />
	 <script type="text/javascript" src='http://127.0.0.1/huaweishop/Static/Admin/Js/goods.js'></script>
	 <script type="text/javascript" src="http://127.0.0.1/huaweishop/Static/uploadify/jquery-1.8.2.min.js"></script>
	<script type="text/javascript" src="http://127.0.0.1/huaweishop/Static/uploadify/jquery.uploadify.min.js"></script>
	<link href="http://127.0.0.1/huaweishop/Static/uploadify/uploadify.css" type="text/css" rel="stylesheet">
   
	  <!--编辑器-->
	<script type="text/javascript" charset="utf-8" src="http://127.0.0.1/huaweishop/Static/ueditor/ueditor.config.js"></script>
	<script type="text/javascript" charset="utf-8" src="http://127.0.0.1/huaweishop/Static/ueditor/ueditor.all.min.js"> </script>
	<script type="text/javascript" charset="utf-8" src="http://127.0.0.1/huaweishop/Static/ueditor/lang/zh-cn/zh-cn.js"></script>	
	<style type="text/css">
		/*去掉uploadify上传按钮的边框*/
	    .uploadify-button {
	        background-color: transparent;
	        border: none;
	        padding: 0;
	    }
	    .uploadify:hover .uploadify-button {
	        background-color: transparent;
    	}
    	.hide{
    		display: none;
    	}
    	body{
    		margin-bottom: 100px;
    	}
	</style> 
	 <script type="text/javascript">
			//让上传按钮显示
			function uploadifyShow(){
        			 $('#pic').uploadify({
        			 	
                    'formData'     : {//POST数据
                        '<?php echo session_name();?>' : '<?php echo session_id();?>',
                    },
                    'fileTypeDesc' : '上传文件',//上传描述
                    'fileTypeExts' : '*.jpg;*.png',
                    'swf'      : 'http://127.0.0.1/huaweishop/Static/uploadify/uploadify.swf',
                    'uploader' : '<?php echo U("upload");?>',
                    'buttonText':'选择文件',
                    'fileSizeLimit' : '2000KB',
                    'uploadLimit' : 1,//上传文件数
                    'width':65,
                    'height':25,
                    'multi': false,//是否多文件上传
                    'successTimeout':10,//等待服务器响应时间
                    'removeTimeout' : 0.2,//成功显示时间
                    'onUploadSuccess' : function(file, data, response) {
                    	//把变量转为json
                        data=$.parseJSON(data);
                        var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+data.url+"' class='img-thumbnail'/><a href='javascript:;' class='del-img'>X</a><input type='hidden' name='pic' value='"+data.path+"' /></li>";
	                            $("#uploadList ul").prepend(li);
                    }
                });
	        }
            $(function(){
            		//刷新页面让上传插件显示
            		uploadifyShow();
            		//点击x，隐藏图片，并且上传按钮显示
	  			$('.del-img').live('click',function(){	  				
	  				$(this).parent('li').hide();
	  				uploadifyShow();
	  				
	  			})
            });
        </script>
        <script type="text/javascript">
			//让上传按钮显示
			function uploadifyShowp(){
        			 $('#photo').uploadify({
        			 	
                    'formData'     : {//POST数据
                        '<?php echo session_name();?>' : '<?php echo session_id();?>',
                    },
                    'fileTypeDesc' : '上传文件',//上传描述
                    'fileTypeExts' : '*.jpg;*.png',
                    'swf'      : 'http://127.0.0.1/huaweishop/Static/uploadify/uploadify.swf',
                    'uploader' : '<?php echo U("uploadphoto");?>',
                    'buttonText':'选择文件',
                    'fileSizeLimit' : '2000KB',
                    'uploadLimit' : 0,//上传文件数
                    'width':65,
                    'height':25,
                    'multi': true,//是否多文件上传
                    'successTimeout':10,//等待服务器响应时间
                    'removeTimeout' : 0.2,//成功显示时间
                    'onUploadSuccess' : function(file, data, response) {
                    	//把变量转为json
                        data=$.parseJSON(data);
                        var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+data.url+"' class='img-thumbnail'/><a href='javascript:;' class='del-img'>X</a><input type='hidden' name='photo[]' value='"+data.path+"' /></li>";
	                            $("#uploadListp ul").prepend(li);
                    }
                });
	        }
           
	  			
           
        </script>
        <script type="text/javascript">
        	$(function(){
        		uploadifyShowp();
        		$(".del-img").live('click',function(){
        			var imgUrl=$(this).parent("li").attr("path");
        			var li=$(this).parent("li");
        			li.remove();       			
        			uploadifyShowp();
        		})
        	})
        </script>
        <script type="text/javascript">
        	$(function(){
        		$("select[name=category_cid]").change(function(){
        			var cid=$(this).val();
        			var tid = $(':selected', this).attr('tid');
        			if (tid == 0){
								alert('顶级分类不能添加商品');
								return;
							}

        			$.ajax({
        				type:"post",
        				url:"<?php echo U('attrajax');?>",
        				data:{cid:cid},
        				dataType:'json',
        				success:function(phpdata){
        					var str="";
        					var opt="<option value='0'>请选择</option>";
        					var st="";
        					var op="<option value='0'>请选择</option>";
	        				   $.each(phpdata, function(k,v) {
		        				   	if(v.class==0){
		        				   		$.each(v.tavalue, function(key,value) {
			        				   		opt+="<option value='"+value+"'>"+value+"</option>";
			        				   	
			        				   	});
			        				   
			        				   	 str+="<tr class='info'><td>"+v.taname+"</td><td>"+"<select name='attr["+v.taid+"]'>"+opt+"</select></td> </tr>";   
			        				   	 opt="<option value='0'>请选择</option>";
		        				   	}else{
		        				   		$.each(v.tavalue, function(key,value) {
			        				   		op+="<option value='"+value+"'>"+value+"</option>";
			        				   	
			        				   	});
			        				   
			        				   	 st+="<tr class='info'><td>"+v.taname+"</td><td>"+"<select name='spec["+v.taid+"][value][]'>"+op+"</select></td><td><input type='text' name='spec["+v.taid+"][added][]' /></td><td><p class='btn btn-primary add_spec'>附加价格</p></td> </tr>";   
			        				   	 op="<option value='0'>请选择</option>";
		        				   		
		        				   	}
		        				   	
	        				   });
	        				   $('#attr').html(str);
	        				   $('#spec').html(st);
        				   
   
        				}
        			});
        			
        			
        		});
        		$(".add_spec").live("click",function(){
        			var Parentr= $(this).parents('tr');
        			var tr=Parentr.clone();
        			Parentr.after(tr);
        			tr.find("p").removeClass("btn-primary add_spec").addClass("btn-danger remove_spec").html("删除规格");
        			
        			
        		});
        		//删除规格
        		$(".remove_spec").live("click",function(){
        			$(this).parents('tr').remove();
        		});
        		
        		
        		
        	})
        </script>
	
</head>
<body>
	<div class="container-fluid">
	<div class="row-fluid">
	<div class="span12">

	<form action="<?php echo U('Goods/edit');?>" method='post'>
		<fieldset>
			<legend>编辑商品</legend>
			<table class='table table-bordered table-hover'>
				<thead>
					<tr>
						<th colspan="2" class="btn btn-primary">基本信息</th>
					</tr>
				</thead>
				<tbody>
					<tr class="info">
						<td>所属分类</td>
						<td>
							<select name="category_cid">
								<option value="0">-请选择-</option>
								<?php foreach ($cateData as $k=>$v){?> 
									<option value="<?php echo $v['cid'];?>"      <?php if($data['category_cid']==$v['cid']){ ?>selected="selected"<?php } ?>  tid='<?php echo $v['pid'];?>'><?php echo $v['_name'];?></option>
								<?php }?>
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>所属品牌</td>
						<td>
							<select name="brand_bid">
								<option value="0">-请选择-</option>
								<?php foreach ($brand as $k=>$v){?>
									<option value="<?php echo $v['bid'];?>"      <?php if($data['brand_bid']==$v['bid']){ ?>selected="selected"<?php } ?>  ><?php echo $v['bname'];?></option>
								<?php }?>
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>商品名称</td>
						<td>
							<input type="text" name='gname' value="<?php echo $data['gname'];?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>单位</td>
						<td>
							<input type="text" name='unit' value='件'/>
						</td>
					</tr>
					<tr class="info">
						<td>商城价</td>
						<td>
							<input type="text" name='price' value="<?php echo $data['price'];?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>点击次数</td>
						<td>
							<input type="text" name='click' value="<?php echo $data['click'];?>"/>
						</td>
					</tr>
				</tbody>
			</table>

			<p class="btn btn-primary">商品属性</p>
			<table class="table table-bordered table-hover" id='attr' class="info">
			  <?php foreach ($allattr as $k=>$val){?>
				
				<tr class='info'>
					<td>
						<?php echo $val['taname'];?>
				    </td>
					<td>
						
						<select name='attr[<?php echo $val['taid'];?>]'>
							<option value="0">请选择</option>
							<?php foreach ($val['tavalue'] as $key=>$attr){?>
							<option value="<?php echo $attr;?>"     <?php if($val['gtvalue']==$attr){ ?>selected="selected"<?php } ?>  ><?php echo $attr;?></option>
							<?php }?>
						</select>
					</td>
					
				</tr>
				
				<?php }?>
			</table>
			<p class="btn btn-primary">商品规格</p>
			<table class="table table-bordered table-hover" id='spec'>
			<?php foreach ($allapec as $k=>$v){?>
				<tr class='info'>
					<td>
						<?php echo $v['taname'];?>
				    </td>
					<td>
						<select name='spec[<?php echo $v['taid'];?>][value][]'>
							<option value="0">请选择</option>
							<?php foreach ($v['tavalue'] as $key=>$spec){?>
							<option   value="<?php echo $spec;?>"     <?php if($v['gtvalue']==$spec){ ?>selected="selected"<?php } ?>  ><?php echo $spec;?></option>
							<?php }?>
						</select>
					</td>
					<td>
						<input type='text' name='spec[<?php echo $v['taid'];?>][added][]' value="<?php echo $v['added'];?>"  />
							
					</td>
					<td>
						<p btn="<?php echo $v['taname'];?>" class='btn b btn-danger remove_spec'>删除规格</p>
					</td>
				</tr>
				<script type="text/javascript">
				    
					$(".btn[btn=<?php echo $v['taname'];?>]").first().removeClass("remove_spec btn-danger").addClass("add_spec btn-primary").html("添加价格");
				   
				</script>
				<?php }?>
				
			</table>

			<table class='table table-bordered'>
				<tr>
					<th colspan="3" class="btn btn-primary">列表图</th>
				</tr>
				<tr class="info">
					<td>上传图片</td>
					<td>
						<input type="file" name='pic' id='pic'/>
						<div id="uploadList">
			                <ul>
			                	    <?php if($data['pic']){ ?>
			                	<li>
			                			<img src='http://127.0.0.1/huaweishop/<?php echo $data['pic'];?>'width="100"  class='img-thumbnail'/>
			                			<a href='javascript:;' class='del-img'>X</a>
			                			<input type='hidden' name='pic' value='<?php echo $data['pic'];?>' />
			                			
			                		</li>
			                	<?php } ?>	
			                </ul>
			            </div>
					</td>
					<td id='pic-list'></td>
				</tr>
			</table>

			<table class='table table-bordered'>
				<tr>
					<th colspan="3" class="btn btn-primary">商品图册</th>
				</tr>
				<tr class="info">
					<td>上传图片</td>
					<td>
						<input type="file" name='photo' id='photo' multiple="true"/>
						<div id="uploadListp">
			                <ul>
			                	
			                		<?php foreach ($detail['photo'] as $k=>$v){?>
			                		    <?php if(!empty($v)){ ?>
			                		<li path="<?php echo $v;?>">
			                			<img src='http://127.0.0.1/huaweishop/<?php echo $v;?>'width="100"  class='img-thumbnail'/>
			                			<a href='javascript:;' class='del-img'>X</a>
			                			<input type='hidden' name='photo[]' value='<?php echo $v;?>' />
			                			
			                		</li>
			                		<?php } ?>
			                		<?php }?>
			                	
			                </ul>
			            </div>
					</td>
					<td id='photo-list'></td>
				</tr>
			</table>

			<table class='table'>
				<tr class="next_show">
					<th class="btn btn-primary">商品详细</th>
				</tr>
				<tr class=" info">
					<td>
			
						    <script id="intro" name="intro" type="text/plain" style="width:1024px;height:500px;"><?php echo $detail['intro'];?></script>
					
						    <script>
						        var ue = UE.getEditor('intro');
						    </script>
					
					</td>
				</tr>
			</table>

			<table class='table'>
				<tr class="next_show">
					<th class="btn btn-primary">售后服务</th>
				</tr>
				<tr class=" info">
					<td>
						 <script id="service" name="service"  type="text/plain" style="width:1024px;height:500px;"><?php echo $detail['service'];?></script>
					
						    <script>
						        var ue = UE.getEditor('service');
						    </script>
					</td>
				</tr>
			</table>
			
			<input type="hidden" name='shop_type_tid' value='<?php echo $hd['get']['tid'];?>'/>
			<input type="hidden" name='gid' value='<?php echo $hd['get']['gid'];?>'/>
			
			<input type="submit" value="确认添加" class="btn btn-primary btn-block btn-large" />
		</fieldset>
	</form>

	</div>
	</div>
	</div>
</body>
</html>